# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=openscad
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2019.05
pkgrel=2
pkgdesc="The programmers solid 3D CAD modeller (mingw-w64)"
arch=('any')
license=("GPL2")
url="http://openscad.org/"
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-cgal"
         "${MINGW_PACKAGE_PREFIX}-double-conversion"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libzip"
         "${MINGW_PACKAGE_PREFIX}-opencsg"
         "${MINGW_PACKAGE_PREFIX}-qscintilla"
         "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-imagemagick")
options=(!strip staticlibs)
source=("https://files.openscad.org/${_realname}-${pkgver}.src.tar.gz")
sha256sums=('0a16c4263ce52380819dd91c609a719d38f12f6b8c4da0e828dcbe5b70996f59')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #rm -f libraries/MCAD/*.py
}

build() {
  msg2 "Will be in future"
  # [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  # mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}
  
  # MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  # ${MINGW_PREFIX}/bin/cmake.exe \
    # -G"MSYS Makefiles" \
    # -DCMAKE_PREFIX_PATH=${MINGW_PREFIX} \
    # -DCMAKE_BUILD_TYPE=Release \
    # ../${_realname}-${pkgver}
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  convert "${srcdir}/${_realname}-${pkgver}/icons/${_realname}.png" -resize 128x128\> "${srcdir}/${_realname}-${pkgver}/icons/${_realname}-128.png"
  BOOSTDIR=${MINGW_PREFIX} \
  CGALDIR=${MINGW_PREFIX} \
  EIGENDIR=${MINGW_PREFIX} \
  GLEWDIR=${MINGW_PREFIX} \
  OPENCSGDIR=${MINGW_PREFIX} \
  ${MINGW_PREFIX}/bin/qmake CONFIG+=release PREFIX="${pkgdir}${MINGW_PREFIX}" VERSION="${pkgver}"

  make
  make INSTALL_ROOT= install
  install -Dm644 "icons/${_realname}.xml" "${pkgdir}${MINGW_PREFIX}/share/mime/packages/${_realname}.xml"
  install -Dm644 COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  
  # cd build-${MINGW_CHOST}
  # make DESTDIR=${pkgdir} install
  # install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING

}
